/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package meg.web.util;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

/**
 *
 * @author radek
 */
public class FacesMessageUtil {
    private static final String EMPTY_DETAIL = "";
    private FacesMessageUtil(){} //singleton

    public static void info(String summary) {
        log(null, FacesMessage.SEVERITY_INFO, summary, EMPTY_DETAIL);
    }

    public static void info(String clientId, String summary) {
        log(clientId, FacesMessage.SEVERITY_INFO, summary, EMPTY_DETAIL);
    }

    public static void info(String clientId, String summary, String detail) {
        log(clientId, FacesMessage.SEVERITY_INFO, summary, detail);
    }

    public static void warn(String summary) {
        log(null, FacesMessage.SEVERITY_WARN, summary, EMPTY_DETAIL);
    }

    public static void warn (String clientId, String summary) {
        log(clientId, FacesMessage.SEVERITY_WARN, summary, EMPTY_DETAIL);
    }
    
    public static void warn(String clientId, String summary, String detail) {
        log(clientId, FacesMessage.SEVERITY_WARN, summary, detail);
    }
    
    public static void error(String summary) {
        log(null, FacesMessage.SEVERITY_ERROR, summary, EMPTY_DETAIL);
    }
    
    public static void error(String clientId, String summary) {
        log(clientId, FacesMessage.SEVERITY_ERROR, summary, EMPTY_DETAIL);
    }
    
    public static void error(String clientId, String summary, String detail) {
        log(clientId, FacesMessage.SEVERITY_ERROR, summary, detail);
    }
    
    public static void fatal(String summary) {
        log(null, FacesMessage.SEVERITY_FATAL, summary, EMPTY_DETAIL);
    }
    
    public static void fatal(String clientId, String summary) {
        log(clientId, FacesMessage.SEVERITY_FATAL, summary, EMPTY_DETAIL);
    }
    
    public static void fatal(String clientId, String summary, String detail) {
        log(clientId, FacesMessage.SEVERITY_FATAL, summary, detail);
    }

    private static void log(String clientId, FacesMessage.Severity severity, String summary, String detail) {
        FacesContext.getCurrentInstance().addMessage(clientId, new FacesMessage(severity, summary, detail));
    }
}
